 package com.smartalarmclock.UI;

import java.util.ArrayList;

import com.smartalarmclock.Logic.AcSyncService;
import com.smartalarmclock.UI.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class MainMenuActivity extends Activity {
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // requestWindowFeature(Window.FEATURE_LEFT_ICON);
        setContentView(R.layout.main_menu);
       // setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_alert);
        
        Intent acSyncService = new Intent(MainMenuActivity.this, AcSyncService.class);
        startService(acSyncService);
        
        final ArrayList<MainMenuItemDetails> image_details = GetSearchResults();
        
        final ListView lv1 = (ListView) findViewById(R.id.listV_main);
        lv1.setAdapter(new ItemListBaseAdapter(this, image_details));
        
        lv1.setOnItemClickListener(new OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView<?> parent, View view,
        			int position, long id) {
        		if("Profile".equals(image_details.get(position).getName()))
        		{
        			Intent profileActivity = new Intent(MainMenuActivity.this,ProfileActivity.class);     
        			startActivity(profileActivity);
        		}
        		else if("VIP".equals(image_details.get(position).getName()))
        		{
        			Intent vipActivity = new Intent(MainMenuActivity.this,VIPActivity.class);     
        			startActivity(vipActivity);
        		}
        		else if("Group".equals(image_details.get(position).getName()))
        		{
        			Intent groupActivity = new Intent(MainMenuActivity.this,GroupActivity.class);     
        			startActivity(groupActivity);
        		}
        		else if("History".equals(image_details.get(position).getName()))
        		{
        			Intent historyActivity = new Intent(MainMenuActivity.this,HistoryActivity.class);     
        			startActivity(historyActivity);
        		}
        		else if("Schedule".equals(image_details.get(position).getName()))
        		{
        			Intent scheduleActivity = new Intent(MainMenuActivity.this,ScheduleActivity.class);     
        			startActivity(scheduleActivity);
        		}
        }
    });

        
 /*       
        lv1.setOnItemClickListener(new OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
        		Object o = lv1.getItemAtPosition(position);
            	MainMenuItemDetails obj_itemDetails = (MainMenuItemDetails)o;
        		Toast.makeText(MainMenuActivity.this, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
        	}  
        });
        */
    }
    
    private ArrayList<MainMenuItemDetails> GetSearchResults(){
    	ArrayList<MainMenuItemDetails> results = new ArrayList<MainMenuItemDetails>();
    	
    	MainMenuItemDetails item_details = new MainMenuItemDetails("Profile", 1);
    	results.add(item_details);
    	
    	item_details = new MainMenuItemDetails("VIP", 2);
    	results.add(item_details);
    	
    	item_details = new MainMenuItemDetails("Group", 3);
    	results.add(item_details);
    	
    	item_details = new MainMenuItemDetails("History", 4);
    	results.add(item_details);
    	
    	item_details = new MainMenuItemDetails("Schedule", 5);
    	results.add(item_details);
    	
    	return results;
    }
}